home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / bawk2a.arc / BAWK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-26  |  6.3 KB  |  234 lines

  1. /*
  2.  * Bawk constants and variable declarations.
  3.  */
  4. #ifdef BDS_C
  5. #define EXTERN /* */
  6. #else
  7.  
  8. #ifdef MAIN
  9. #define EXTERN /* */
  10. #else
  11. #define EXTERN extern
  12. #endif
  13.  
  14. #endif
  15.  
  16.  
  17. #define DEBUG 1     /* remove this line to compile without debug statements */
  18. #ifdef DEBUG    
  19. EXTERN char Debug; /* debug print flag */
  20. #endif
  21.  
  22. /*
  23.  * Table and buffer sizes
  24.  */
  25. #define MAXLINELEN 128              /* longest input line */
  26. #define MAXWORDS (MAXLINELEN/2)     /* max # of words in a line */
  27. #define MAXWORKBUFLEN 4096          /* longest action or regular expression */
  28. #define MAXVARTABSZ 50              /* max # of symbols */
  29. #define MAXVARLEN 10                /* symbol name length */
  30. #define MAXSTACKSZ 40               /* max stack length (for expressions) */
  31.  
  32.  
  33. /**********************************************************
  34.  * Current Input File variables                           *
  35.  **********************************************************/
  36. /*
  37.  * Current Input File pointer:
  38.  */
  39. #ifdef BDS_C
  40. EXTERN char *Fileptr, Curfbuf[ BUFSIZ ];
  41. #else
  42. EXTERN FILE *Fileptr;
  43. #endif
  44. EXTERN char *Filename;               /* current input file name */
  45. EXTERN int Linecount;                /* current input line number */
  46. EXTERN int Recordcount;              /* record count */
  47. /*
  48.  * Working buffers.
  49.  */
  50. EXTERN char Linebuf[ MAXLINELEN ];      /* current input line buffer */
  51. EXTERN char *Fields[ MAXWORDS ];        /* pointers to the words in Linebuf */
  52. EXTERN int Fieldcount;                  /* and the # of words */
  53. EXTERN char Workbuf[ MAXWORKBUFLEN ];   /* work area for C action and */
  54.  
  55.  
  56. /**********************************************************
  57.  * Regular Expression Parser variables                    *
  58.  **********************************************************/
  59. /*
  60.  * Tokens:
  61.  */
  62. #define CHAR 1
  63. #define BOL 2
  64. #define EOL 3
  65. #define ANY 4
  66. #define CLASS 5
  67. #define NCLASS 6
  68. #define STAR 7
  69. #define PLUS 8
  70. #define MINUS 9
  71. #define ALPHA 10
  72. #define DIGIT 11
  73. #define NALPHA 12
  74. #define PUNCT 13
  75. #define RANGE 14
  76. #define ENDPAT 15
  77.  
  78.  
  79. /**********************************************************
  80.  * C Actions Interpreter variables                        *
  81.  **********************************************************/
  82. /*
  83.  * Tokens:
  84.  */
  85. #define T_STRING 'S'               /* primaries: */
  86. #define T_DOLLAR '$'
  87. #define T_REGEXP 'r'
  88. #define T_CONSTANT 'C'
  89. #define T_VARIABLE 'V'
  90. #define T_FUNCTION 'F'
  91. #define T_SEMICOLON ';'            /* punctuation */
  92. #define T_EOF 'Z'
  93. #define T_LBRACE '{'
  94. #define T_RBRACE '}'
  95. #define T_LPAREN '('
  96. #define T_RPAREN ')'
  97. #define T_LBRACKET '['
  98. #define T_RBRACKET ']'
  99. #define T_COMMA ','
  100. #define T_ASSIGN '='               /* operators: */
  101. #define T_MUL '*'
  102. #define T_DIV '/'
  103. #define T_MOD '%'
  104. #define T_ADD '+'
  105. #define T_SUB '-'
  106. #define T_SHL 'L'
  107. #define T_SHR 'R'
  108. #define T_LT '<'
  109. #define T_LE 'l'
  110. #define T_GT '>'
  111. #define T_GE 'g'
  112. #define T_EQ 'q'
  113. #define T_NE 'n'
  114. #define T_NOT '~'
  115. #define T_AND '&'
  116. #define T_XOR '^'
  117. #define T_IOR '|'
  118. #define T_LNOT '!'
  119. #define T_LAND 'a'
  120. #define T_LIOR 'o'
  121. #define T_INCR 'p'
  122. #define T_DECR 'm'
  123. #define T_IF 'i'                   /* keywords: */
  124. #define T_ELSE 'e'
  125. #define T_WHILE 'w'
  126. #define T_BREAK 'b'
  127. #define T_CHAR 'c'
  128. #define T_INT 't'
  129. #define T_BEGIN 'B'
  130. #define T_END 'E'
  131. #define T_NF 'f'
  132. #define T_NR '#'
  133. #define T_FS ' '
  134. #define T_RS '\n'
  135. #define T_FILENAME 'z'
  136.  
  137. #define PATTERN 'P'            /* indicates C statement is within a pattern */
  138. #define ACTION 'A'             /* indicates C statement is within an action */
  139.  
  140. /*
  141.  * Symbol Table values
  142.  */
  143. #define ACTUAL 0
  144. #define LVALUE 1
  145. #define BYTE 1
  146. #define WORD 2
  147. /*
  148.  * Symbol table
  149.  */
  150. struct variable {
  151.     char vname[ MAXVARLEN ];
  152.     char vclass;
  153.     char vsize;
  154.     int vlen;
  155.     char *vptr;
  156.     };
  157.  
  158. #define VARIABLE struct variable
  159. EXTERN VARIABLE Vartab[ MAXVARTABSZ ], *Nextvar;
  160.  
  161. /*
  162.  * Value stack
  163.  */
  164. union datum {
  165.     int ival;
  166.     char *dptr;
  167.     char **ptrptr;
  168.     };
  169. #define DATUM union datum
  170.  
  171. struct item {
  172.     char class;
  173.     char lvalue;
  174.     char size;
  175.     DATUM value;
  176.     };
  177. #define ITEM struct item
  178. EXTERN ITEM Stackbtm[ MAXSTACKSZ ], *Stackptr, *Stacktop;
  179.  
  180. /*
  181.  * Miscellaneous
  182.  */
  183. EXTERN char *Actptr;             /* pointer into Workbuf during compilation */
  184. EXTERN char Token;               /* current input token */
  185. EXTERN DATUM Value;              /* and its value */
  186. EXTERN char Saw_break;           /* set when break stmt seen */
  187. EXTERN char Where;       /* indicates whether C stmt is a PATTERN or ACTION */
  188. EXTERN char Fieldsep[3];         /* field seperator */
  189. EXTERN char Recordsep[3];        /* record seperator */
  190. EXTERN char *Beginact;           /* BEGINning of input actions */
  191. EXTERN char *Endact;             /* END of input actions */
  192.  
  193. /**********************************************************
  194.  * Rules structure                                        *
  195.  **********************************************************/
  196. struct rule {
  197.     struct {
  198.         char *start;                /* C statements that match pattern start */
  199.         char *stop;                 /* C statements that match pattern end */
  200.         char startseen;             /* set if both a start and stop pattern */
  201.                                   /* given and if an input line matched the */
  202.                                   /* start pattern */
  203.         }
  204.     pattern;
  205.     char *action;                  /* contains quasi-C statements of actions */
  206.     struct rule *nextrule;         /* pointer to next rule */
  207.     };
  208. #define RULE struct rule
  209. EXTERN RULE *Rules,               /* rule structures linked list head */
  210. *Rulep;                           /* working pointer */
  211.  
  212.  
  213. /**********************************************************
  214.  * Miscellaneous                                          *
  215.  **********************************************************/
  216. /*
  217.  * Error exit values (returned to command shell)
  218.  */
  219. #define USAGE_ERROR 1             /* error in invokation */
  220. #define FILE_ERROR 2              /* file not found errors */
  221. #define RE_ERROR 3                /* bad regular expression */
  222. #define ACT_ERROR 4               /* bad C action stmt */
  223. #define MEM_ERROR 5               /* out of memory errors */
  224.  
  225. /*
  226.  * Functions that return something special:
  227.  */
  228. char *str_compile(), *getmem(), *cclass(), *pmatch(), *fetchptr();
  229. VARIABLE *findvar(), *addvar(), *decl();
  230.  
  231.  
  232.  
  233.  
  234.